package com.jz.community.moduleshoppingguide.nearshop.ui.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.glideConfig.GlideApp;
import com.jz.community.basecomm.utils.RoundCornersTransformation;
import com.jz.community.basecomm.utils.SHelper;
import com.jz.community.moduleshoppingguide.R;

import java.util.List;


/**
 * Created by Andy Huang on 2018/3/5.
 *
 * @description:
 */

public class ShopInfoImageListAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
    private int screen_width;
    private int screen_height;

    public ShopInfoImageListAdapter(int layoutResId, @Nullable List<String> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {

    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        //获取屏幕宽高
        WindowManager wm = (WindowManager) mContext.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
        assert wm != null;
        screen_width = wm.getDefaultDisplay().getWidth();//获取屏幕宽度
        screen_height = wm.getDefaultDisplay().getHeight();//获取屏幕高度
        LinearLayout goods_parent = holder.getView(R.id.ll_shop_info_pop_picture);
        ImageView iv_shop_info_image = holder.getView(R.id.iv_shop_info_image);
        ViewGroup.LayoutParams lp1 = goods_parent.getLayoutParams();
        int parent_width = ((screen_width - SHelper.dp2px(mContext, 56)) / 7) * 2;
        lp1.width = parent_width;
        goods_parent.setLayoutParams(lp1);

        ViewGroup.LayoutParams lp_img = iv_shop_info_image.getLayoutParams();

        lp_img.width = 2 * parent_width;//- RxImageTool.dp2px(10)
        lp_img.height = 2 * parent_width; // RxImageTool.dp2px(10);
        iv_shop_info_image.setLayoutParams(lp_img);
        RoundCornersTransformation transformation = new RoundCornersTransformation(mContext,
                SHelper.dp2px(mContext, 5), RoundCornersTransformation.CornerType.ALL);
        GlideApp.with(mContext)
                .load(mData.get(position))
                .transform(transformation)
                .placeholder(R.mipmap.image_default)
                .error(R.mipmap.image_default)
                .into(iv_shop_info_image);
    }



}
